package com.ys.timer;

import com.ys.service.report.TcoBusinessDataStatService;
import com.ys.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;

import java.util.Date;


//运营数据统计表
@Controller
public class TimerTcoBusinessDataStatDaily {
	private static final Logger logger = LoggerFactory.getLogger(TimerTcoBusinessDataStatDaily.class);

    @Autowired
    private TcoBusinessDataStatService tcoBusinessDataStatService;

	//每天8点30执行，统计当日数据
	@Scheduled(cron = "0 30 8 * * * ")
	public void countTcoBusinessDataStat() {
		try {
			logger.info("***********定时统计运营数据统计表开始***********");
			String countMonth = DateUtil.getYYYY_MM(new Date());

			//刷取前1个月数据
			String oldMonthOne = DateUtil.getYYYY_MM(DateUtil.addMonth(countMonth,-1));

			//刷取前2个月数据
			String oldMonthTwo = DateUtil.getYYYY_MM(DateUtil.addMonth(countMonth,-2));

			//刷取月数据
			tcoBusinessDataStatService.count(oldMonthOne);
			tcoBusinessDataStatService.count(oldMonthTwo);

			//刷取年累计数据
			tcoBusinessDataStatService.countYearAdded(oldMonthOne);
			tcoBusinessDataStatService.countYearAdded(oldMonthTwo);

			//1号不刷当月数据
			String dayNum = DateUtil.getDD(new Date());
			if(!dayNum.equals("01")){
				tcoBusinessDataStatService.count(countMonth);
				tcoBusinessDataStatService.countYearAdded(countMonth);
			}

			logger.info("***********定时统计运营数据统计表完成***********");
		}catch (Exception e){
			//e.printStackTrace();
			logger.error("定时统计运营跟踪表数据出错：",e.getMessage(),e);
		}
	}


	
}
